package pluginUtils;

public class Sphere {
	private static String[] palette={"Yellow","Red","Blue","Yellow","White","NavyBlue","Turquoise","Orange"};
	
	private double radius;
	private Pos3D center;
	private int colorIndex=0; 
	

	public Pos3D getCenter(){return this.center;}
	
	/**
	 * @return the radius
	 */
	public double getRadius() {
		return radius;
	}
	
	public void setRadius(double r){this.radius=r;}
	
	public double distance(Sphere s){
		return Pos3D.distance(this.center, s.center)
; 	}
	

	
	public Sphere(Pos3D X, double radius) {
		super();
		this.center=new Pos3D(X); 
		this.radius = radius;
	} 
	
	/** Return true if Sphere s and this intersect */
	public boolean intersects(Sphere s){
		return(this.distance(s)<(this.radius+s.radius)); 
	}
	
	
	
	public String toString(){
		double x=center.getX(); 
		double y=center.getY(); 
		double z=center.getZ(); 
		String s="sphere{<"+x+","+y+","+z+">,"+radius+" texture{pigment{color "+palette[this.colorIndex]+"}} finish {reflection 0.6 }}";
		return s; 
	}
	
	public String printSphere(double a,double b,double c)
	{
		double x=center.getX(); 
		double y=center.getY(); 
		double z=center.getZ(); 
		String s="sphere{<"+x+","+y+","+z+">,"+radius+" texture{pigment{color rgb<"+a+","+b+","+c+">}} finish {reflection 0.6 }}";
		return s; 
	}

	/**
	 * @param colorIndex the colorIndex to set
	 */
	public void setColorIndex(int colorIndex) {
		this.colorIndex = colorIndex;
	}

	public int getColorIndex() {
		return this.colorIndex; 
	}
	
	public boolean isIncludedIn(Sphere ci){
		double dcenters=Pos3D.distance(this.center,ci.center);
		return dcenters+this.radius<ci.radius; 
	}
	
}
